package com.pure.common.utils;

import lombok.extern.slf4j.Slf4j;

import java.time.LocalDateTime;
import java.time.Month;
import java.time.ZoneId;
import java.time.temporal.TemporalField;
import java.util.Calendar;
import java.util.Date;

/**
 * @description: 日期工具类
 * @date: 2022-07-06 09:04
 * @since 1.2.0
 **/
@Slf4j
public class PureDateUtils {

    public static void main(String[] args) {

        long l = parseDate(new Date());
        log.info("epoch second is", l);

    }

    public static long parseDate(Date currentDateTime) {

        Calendar cld = Calendar.getInstance();
        cld.setTime(currentDateTime);

        int year = cld.get(Calendar.YEAR);
        log.info("year is {}", year);
        Month month = Month.of(cld.get(Calendar.MONTH) + 1);
        log.info("month is {}", month);
        int day = cld.get(Calendar.DATE);
        log.info("day is {}", day);
        int hour = cld.get(Calendar.HOUR_OF_DAY);
        log.info("hour is {}", hour);
        int minute = cld.get(Calendar.MINUTE);
        log.info("minute is {}", minute);

        LocalDateTime localDateTime = LocalDateTime.of(year, month, day, hour, minute);
        long epochSecond = localDateTime.atZone(ZoneId.systemDefault()).toEpochSecond();
        log.info("epoch second is {}", epochSecond);
        return epochSecond;
    }
}
